<?php

$user_obj = new user_obj();
$client_obj = new client_obj();

if (isset($_REQUEST['action'])){
    switch ($_REQUEST['action']) {
        case 'add_client':
            $client = $_REQUEST['client'];
            $client['monthlyFee'] = str_replace(',', '.', $client['monthlyFee']);
            if (substr($client['domain'], 0, 1) == '@'){
                $client['domain'] = substr($client['domain'], 1);
            }
            
            $newId = $client_obj->addClient($client);
            if (error_obj::isError($newId)){
                error_obj::setError($newId, UNEXCEPTED);
            } else {
                base_obj::redirect(ROOT . '?input=list_of_clients');
            }
            
            break;
    }
}

$filter = array();
$filter['active'] = 1;
$filter['client'] = 11;
$client['contactPersons'] = $user_obj->getUsers('name, surname, users_id',$filter);
$client['typesOfCoop'] = $client_obj->getClientTypeOfCooperations();

$GLOBALS['template_data'] = $client;
?>
